import sys
import csv

#Ã¥Â¤ÂÃ§ÂÂÃ¥ÂÂ½Ã¤Â»Â¤Ã¨Â¡ÂÃ¥ÂÂÃ¦ÂÂ°Ã§Â±Â»
class Args:
    def __init__(self):
        args = sys.argv[1:]
        self.c = args[args.index('-c')+1]
        self.d = args[args.index('-d')+1]
        self.o = args[args.index('-o')+1]
#       print(self.c,self.d,self.o)     
args=Args()
#print(args)

class Config:
    def __init__(self):
        self.config=self._read_config()
    def _read_config(self):
        config={'s': 0}
        with open(args.c) as file:
            for x in file.readlines():
                a, b = x.split('=')
                a, b = a.strip(), float(b)
                if a == 'JiShuL' or a == 'JiShuH':
                    config[a] = b
                else:
                    config['s'] += b
        return config

config = Config().config

class UserData:
    def __init__(self):
        with open(args.d) as f:
            data = list(csv.reader(f))
        self.data = data

userdata = UserData().data

def cal(num, salary):
    l = []
    shebao = salary * config['s']
    if salary < config['JiShuL']:
        shebao = config['JiShuL'] * config['s']
    if salary > config['JiShuH']:
        shebao = config['JiShuH'] * config['s']
    a = salary - shebao - 3500
    if a > 80000:       #应纳税
        s=a*0.45-13505
    elif a > 55000:
        s=a*0.35-5505
    elif a > 35000:
        s=a*0.3-2755
    elif a > 9000:
        s=a*0.25-1005
    elif a > 4500:
        s=a*0.2-555
    elif a > 1500:
        s=a*0.1-105
    elif a > 0:
        s=a*0.03-0
    else:
        s=0
    shgz = salary - shebao - s
    return [num, salary, format(shebao, '.2f'), format(s, '.2f'), format(shgz, '.2f')]
with open(args.o, 'a') as f:
    for a, b in userdata:
        csv.writer(f).writerow(cal(a, int(b)))
